import './HomeTempConfig.scss'
import { FormTemplate } from '../../Utils/FormTemp'

import { ConfigMapping } from '../../Utils/HomeTemplate/BefaultConfig'
import { useEventEmitter } from 'ahooks';

const HomeTempConfig = ({ data, ModalEvent }) => {
    const { type: common, params, i } = data
    const columns = ConfigMapping[common]
    ModalEvent.useSubscription(val => {
        const { type, data } = val
        if (type === 'offLoading') FormEvent.emit({ type: 'offLoading' })
    })
    const FormEvent = useEventEmitter()
    FormEvent.useSubscription(val => {
        const { type, data } = val
        if (type === 'Added') ModalEvent.emit({ type: 'formBack', data: { i, formItem: common, ...data } })
    })
    return (
        <div className='HomeTempConfig'>
            <FormTemplate columns={columns} init={params} ModalEvent={FormEvent} />
        </div>
    );
};

export default HomeTempConfig;